[Wasm R2R] Fix two crossgen2 NYIs: FloatTraits::NaN and bitcast of same-size types#129095
Conversation
…me-i32-size types
Two NYI assertions were firing during wasm crossgen2 of test code:
1. valuenum.cpp:52 NYI_WASM('FloatTraits::NaN') - hit when VN constant-folds
a NaN-producing FP expression (e.g. r4NaNrem.cs). Implement FloatTraits::NaN
and DoubleTraits::NaN for WASM using the WebAssembly canonical NaN
(positive sign, exponent all ones, payload MSB = 1) which matches the bit
pattern produced by V8, SpiderMonkey, and Wasmtime, and aligns with the
ARM convention.
2. codegenwasm.cpp:1891 unreached() in genCodeForBitCast - hit when shared-generic
codegen produces a BITCAST between INT and REF/BYREF (e.g. Comparer_get_Default
Bitcast<__Canon>(long)). On wasm32 these are all i32 on the wasm value stack,
so the bitcast is a true no-op. PackTypes normalizes TYP_REF/TYP_BYREF to
TYP_I_IMPL, so a single case for PackTypes(TYP_INT, TYP_INT) (wasm32) and
PackTypes(TYP_LONG, TYP_LONG) (wasm64) covers all valid combinations.
Remaining unsupported combinations now go through NYI_WASM so that R2R can
fall back gracefully when JitWasmNyiToR2RUnsupported=1.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
Pull request overview
This PR updates CoreCLR JIT WASM support to reduce crossgen2/ReadyToRun “NYI” failures by (1) defining target-appropriate NaN bit patterns for constant folding and (2) treating same-size WASM integer/pointer bitcasts as no-ops where no reinterpret instruction is required.
Changes:
- Implement
FloatTraits::NaN/DoubleTraits::NaNforTARGET_WASMusing a canonical NaN payload. - Update
CodeGen::genCodeForBitCaston WASM to avoid emitting instructions for certain same-size bitcasts, and replace the previousunreached()default with a WASM NYI.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/coreclr/jit/valuenum.cpp | Adds WASM NaN bit patterns for floating-point constant folding. |
| src/coreclr/jit/codegenwasm.cpp | Makes some same-size bitcasts into no-ops and improves unsupported-combination handling. |
- Extend FpAdd/FpSub/FpMul/FpDiv NaN-substitution to TARGET_WASM so constant folding of (+inf)+(-inf), 0*inf, 0/0, inf/inf etc. produces the WASM canonical NaN bit pattern instead of the host's (e.g. x64's 0xFFC00000), keeping crossgen2 output consistent with runtime. - Tighten the in-method comments on the WASM bit-pattern selection and on the same-size BITCAST no-op case in genCodeForBitCast. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@adamperlin maybe look at this one too? |
|
@adamperlin can you take a look? |
Yes. Just had one comment about |
Per PR review feedback: the default case in the bitcast type switch should be unreached(), since BITCAST should only be morphed in for supported same-size type pairings.
Per PR review feedback: the NaN-canonicalization paths in FloatTraits::NaN, DoubleTraits::NaN, FpAdd, FpSub, FpMul, and FpDiv now also cover TARGET_LOONGARCH64, TARGET_RISCV64, and TARGET_WASM. Update the doc comments to match the preprocessor guards.
|
/ba-g unrelated failure without console log |
Implement FloatTraits::NaN and DoubleTraits::NaN for WASM using the WebAssembly canonical NaN.
In genCodeForBitCast same sized bit casts are nops.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com